﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BneyBaruch.Ingest.MorningLesson.Services;
using BneyBaruch.Ingest.MorningLesson.Services.Data;
using System.ServiceModel;
using System.Windows.Forms;
using BneyBaruch.Ingest.Utils.FileSystem;
using BneyBaruch.Ingest.Utils;
using System.Threading;

namespace BneyBaruch.Ingest.MorningLesson.CaptureBox.Services
{
    [ServiceBehavior
        (
            InstanceContextMode = InstanceContextMode.Single,
            ConcurrencyMode = ConcurrencyMode.Reentrant
        )
    ]
    public class SplitedVideoCaptureBoxServer : ISplitedVideoCaptureBoxServer
    {
        #region Constants

        private const string DriveName = "m";

        #endregion

        #region ISplitedVideoCaptureBoxServer Members

        public StartManualVideoRecordingResponse StartManualVideoRecording(StartManualVideoRecordingRequest startManualVideoRecordingRequest)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IVideoCaptureBoxServer Members

        public void ReopenCaptureBox()
        {
            throw new NotImplementedException();
        }

        public void PrepareFileSystemBeforeRecording(PrepareFileSystemBeforeRecordingRequest prepareFileSystemBeforeRecordingRequest)
        {
            ISplitedVideoCaptureBoxServerCallback caller = OperationContext.Current.GetCallbackChannel<ISplitedVideoCaptureBoxServerCallback>();
            // Request user in another thread without blocking wcf communication and callback to caller in new thread.
            ThreadPool.QueueUserWorkItem(
                delegate(Object state)
                {
                    MessageBox.Show("Prepare file system on splitted video capture box server started.");
                    FileSystemCleanData fileSystemCleanData = DriveUtil.CleanFileSystemIfNeeded(DriveName, Constants.FiftyGB, DriveName + ":");
                    caller.ReportFileSystemStatus(
                        new FileSystemStatus()
                        {
                            WorkflowInstanceId = prepareFileSystemBeforeRecordingRequest.WorkflowInstanceId,
                            FileSystemCleanStatistics = fileSystemCleanData
                        }
                    );
                }
            );
        }

        public void TestRecordingQuality(TestRecordingQualityRequest testRecordingQualityRequest)
        {
            throw new NotImplementedException();
        }

        public void PrepareCaptureBoxBeforeRecording()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
